package unit;

import junit.framework.TestCase;

import com.google.code.netcheckin.io.Ascii;

public class UAscii extends TestCase {

	public UAscii(String name) {
		super(name);
	}

	public final void testACToUpperByte() {
		byte answer = Ascii.toUpperCase(Ascii.V_A);
		assertEquals("upper already", Ascii.V_A, answer);
		answer = Ascii.toUpperCase(Ascii.V_z);
		assertEquals("from lower z", Ascii.V_Z, answer);
		answer = Ascii.toUpperCase(Ascii.V_COLON);
		assertEquals("from COLON", Ascii.V_COLON, answer);
		answer = Ascii.toUpperCase(Ascii.V_BACK_QUOTE);
		assertEquals("from BACK_QUOTE", Ascii.V_BACK_QUOTE, answer);
		answer = Ascii.toUpperCase(Ascii.V_BRACELEFT);
		assertEquals("from BRACELEFT", Ascii.V_BRACELEFT, answer);
	}

	public final void testADToUpperArray() {
		byte[] data = new byte[] { Ascii.V_A, Ascii.V_z, Ascii.V_COLON };
		byte[] answer = Ascii.toUpperCase(data);
		assertNotNull("answer null", answer);
		assertEquals("wrong length", data.length, answer.length);
	}

	public final void testToAELowerByte() {
		byte answer = Ascii.toLowerCase(Ascii.V_A);
		assertEquals("upper already", Ascii.V_a, answer);
		answer = Ascii.toLowerCase(Ascii.V_Z);
		assertEquals("from lower z", Ascii.V_z, answer);
		answer = Ascii.toLowerCase(Ascii.V_COLON);
		assertEquals("from COLON", Ascii.V_COLON, answer);
		answer = Ascii.toLowerCase(Ascii.V_BACK_QUOTE);
		assertEquals("from BACK_QUOTE", Ascii.V_BACK_QUOTE, answer);
		answer = Ascii.toLowerCase(Ascii.V_BRACELEFT);
		assertEquals("from BRACELEFT", Ascii.V_BRACELEFT, answer);
	}

	public final void testAFToLowerArray() {
		byte[] data = new byte[] { Ascii.V_A, Ascii.V_z, Ascii.V_COLON };
		byte[] answer = Ascii.toLowerCase(data);
		assertNotNull("answer null", answer);
		assertEquals("wrong length", data.length, answer.length);
	}

	public final void testAGIsDigit() {
		assertTrue("0", Ascii.isDigit(Ascii.V_0));
		assertTrue("9", Ascii.isDigit(Ascii.V_9));
		assertFalse("/", Ascii.isDigit(Ascii.V_SLASH));
		assertFalse(":", Ascii.isDigit(Ascii.V_COLON));
	}

	public final void testAHIsLetter() {
		assertTrue("A", Ascii.isLetter(Ascii.V_A));
		assertTrue("Z", Ascii.isLetter(Ascii.V_Z));
		assertTrue("a", Ascii.isLetter(Ascii.V_a));
		assertTrue("z", Ascii.isLetter(Ascii.V_z));
		assertFalse("@", Ascii.isLetter(Ascii.V_AT));
		assertFalse("[", Ascii.isLetter(Ascii.V_OPEN_BRACKET));
		assertFalse("BACK_QUOTE", Ascii.isLetter(Ascii.V_BACK_QUOTE));
		assertFalse("BRACELEFT", Ascii.isLetter(Ascii.V_BRACELEFT));
	}

	public final void testAIIsLowerCase() {
		assertFalse("A", Ascii.isLowerCase(Ascii.V_A));
		assertFalse("Z", Ascii.isLowerCase(Ascii.V_Z));
		assertTrue("a", Ascii.isLowerCase(Ascii.V_a));
		assertTrue("z", Ascii.isLowerCase(Ascii.V_z));
		assertFalse("@", Ascii.isLowerCase(Ascii.V_AT));
		assertFalse("[", Ascii.isLowerCase(Ascii.V_OPEN_BRACKET));
		assertFalse("BACK_QUOTE", Ascii.isLowerCase(Ascii.V_BACK_QUOTE));
		assertFalse("BRACELEFT", Ascii.isLowerCase(Ascii.V_BRACELEFT));
	}

	public final void testAJIsUpperCase() {
		assertTrue("A", Ascii.isUpperCase(Ascii.V_A));
		assertTrue("Z", Ascii.isUpperCase(Ascii.V_Z));
		assertFalse("a", Ascii.isUpperCase(Ascii.V_a));
		assertFalse("z", Ascii.isUpperCase(Ascii.V_z));
		assertFalse("@", Ascii.isUpperCase(Ascii.V_AT));
		assertFalse("[", Ascii.isUpperCase(Ascii.V_OPEN_BRACKET));
		assertFalse("BACK_QUOTE", Ascii.isUpperCase(Ascii.V_BACK_QUOTE));
		assertFalse("BRACELEFT", Ascii.isUpperCase(Ascii.V_BRACELEFT));
	}

	public final void testAKisWhiteSpace() {
		assertTrue("SP", Ascii.isWhiteSpace(Ascii.V_SP));	// space
		assertTrue("LF", Ascii.isWhiteSpace(Ascii.V_LF));	// line feed
		assertTrue("HT", Ascii.isWhiteSpace(Ascii.V_HT));	// tab
		assertTrue("CR", Ascii.isWhiteSpace(Ascii.V_CR));	// carriage return
		assertTrue("NP", Ascii.isWhiteSpace(Ascii.V_NP));	// form feed
		assertTrue("VT", Ascii.isWhiteSpace(Ascii.V_VT));      // vertical tab
		assertFalse("0", Ascii.isWhiteSpace(Ascii.V_0));
	}

}
